<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>

<!--
	Copyright (c) 1999-2008 by Digital Mars
	All Rights Reserved
	Written by Walter Bright
	www.digitalmars.com
  -->

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
<title>std.utf - D Programming Language - Digital Mars</title>
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="icon" type="image/gif" href="./holy.gif" />
</head>

<body>
<div id="heading">
	<a href="http://www.digitalmars.com/"><img src="./dmlogo.gif" width="270" height="53" border="0" alt="www.digitalmars.com" align="left"></a>
	<p align="right">D Programming Language 1.0</p>


	<div id="headingNav">
	<ul>
	<li><a href="http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos/StdUtf" title="Read/write comments and feedback">Comments</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/index.html" title="D Programming Language" class="dlink">D</a></li>
	<li><a href="http://www.digitalmars.com/advancedsearch.html" title="Search Digital Mars web site">Search</a></li>
	<li><a href="http://www.digitalmars.com/" title="www.digitalmars.com">Home</a></li>
	</ul>
	</div>

	<div id="lastupdate">Last update Wed Oct  1 23:47:53 2008</div>
</div>

<!-- -->

<div id="navigation">
    <div class="navblock">
<form method="get" action="http://www.google.com/search">
<div id="searchbox">
<input id="q" name="q" size="10" value="RTL Search" onFocus='if(this.value == "RTL Search"){this.value="";}'>
<input type="hidden" id="domains" name="domains" value="www.digitalmars.com">
<input type="hidden" id="sitesearch" name="sitesearch" value="www.digitalmars.com/d/1.0/phobos">
<input type="hidden" id="sourceid" name="sourceid" value="google-search">
<input type="submit" id="submit" name="submit" value="Go">
</div>
</form>
<div id="toctop">
    <ul>
	<li><a href="http://www.digitalmars.com/d/1.0/index.html" title="D Programming Language">D ...</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/lex.html" title="D Language Specification">Language ...</a></li>
	<li><a href="phobos.html" title="D Runtime Library">Phobos ...</a></li>
	<li><a href="http://www.digitalmars.com/d/1.0/comparison.html" title="Language Comparisons">Comparisons ...</a></li>
    </ul>
</div>
</div>
    <div class="navblock">
<ul>
<li><a href="index.html" title="Index of all HTML files">Index</a></li>
</ul>
    <ul>
	<li><a href="object.html" title="root of object hierarchy">object</a></li>
    </ul>
    <h2><a href="phobos.html#std" title="D standard modules">std</a></h2>
    <ul>
	<li><a href="std.base64.html" title="Encode/decode base64 format">std.base64</a></li>
	<li><a href="std.bind.html" title="Function argument binding">std.bind</a></li>
	<li><a href="std.bitarray.html" title="Arrays of bits">std.bitarray</a></li>
	<li><a href="std.boxer.html" title="Box/unbox types">std.boxer</a></li>
	<li><a href="std.compiler.html" title="Information about the D compiler implementation">std.compiler</a></li>
	<li><a href="std.conv.html" title="Conversion of strings to integers">std.conv</a></li>
	<li><a href="std.cover.html" title="D coverage analyzer">std.cover</a></li>
	<li><a href="std.cpuid.html" title="CPU identification">std.cpuid</a></li>
	<li><a href="std.ctype.html" title="Simple character classification">std.ctype</a></li>
	<li><a href="std.date.html" title="Date and time functions">std.date</a></li>
	<li><a href="std.demangle.html" title="Demangle D names">std.demangle</a></li>
	<li><a href="std.file.html" title="Basic file operations">std.file</a></li>
	<li><a href="std.format.html" title="Formatted conversions of values to strings">std.format</a></li>
	<li><a href="std.gc.html" title="Control the garbage collector">std.gc</a></li>
	<li><a href="std.intrinsic.html" title="Compiler built in intrinsic functions">std.intrinsic</a></li>
	<li><a href="std.math.html" title="the usual math functions">std.math</a></li>
	<li><a href="std.md5.html" title="Compute MD5 digests">std.md5</a></li>
	<li><a href="std.metastrings.html" title="Metaprogramming with strings">std.metastrings</a></li>
	<li><a href="std.mmfile.html" title="Memory mapped files">std.mmfile</a></li>
	<li><a href="std.openrj.html" title="Basic database">std.openrj</a></li>
	<li><a href="std.outbuffer.html" title="Assemble data into an array of bytes">std.outbuffer</a></li>
	<li><a href="std.outofmemory.html" title="Out of memory exception">std.outofmemory</a></li>
	<li><a href="std.path.html" title="Manipulate file names, path names, etc.">std.path</a></li>
	<li><a href="std.process.html" title="Create/destroy threads">std.process</a></li>
	<li><a href="std.random.html" title="Random number generation">std.random</a></li>
	<li><a href="std.regexp.html" title="regular expressions">std.regexp</a></li>
	<li><a href="std.signals.html" title="Signals">std.signals</a></li>
	<li><a href="std.socket.html" title="Sockets">std.socket</a></li>
	<li><a href="std.socketstream.html" title="Stream for a blocking, connected Socket">std.socketstream</a></li>
	<li><a href="std.stdint.html" title="Integral types for various purposes">std.stdint</a></li>
	<li><a href="std.stdio.html" title="Standard I/O">std.stdio</a></li>
	<li><a href="std.cstream.html" title="Stream I/O">std.cstream</a></li>
	<li><a href="std.stream.html" title="Stream I/O">std.stream</a></li>
	<li><a href="std.string.html" title="Basic string operations">std.string</a></li>
	<li><a href="std.system.html" title="Inquire about the CPU, operating system">std.system</a></li>
	<li><a href="std.thread.html" title="Thread operations">std.thread</a></li>
	<li><a href="std.traits.html" title="Type traits">std.traits</a></li>
	<li><a href="std.typetuple.html" title="Type tuples">std.typetuple</a></li>
	<li><a href="std.uni.html" title="Unicode classification">std.uni</a></li>
	<li><a href="std.uri.html" title="Encode and decode Uniform Resource Identifiers (URIs)">std.uri</a></li>
	<li><a href="std.utf.html" title="Encode and decode utf character encodings">std.utf</a></li>
	<li><a href="std.zip.html" title="Read/write zip archives">std.zip</a></li>
	<li><a href="std.zlib.html" title="Compression / Decompression of data">std.zlib</a></li>
	<li><a href="std.c.fenv.html" title="Floating point environment">std.c.fenv</a></li>
	<li><a href="std.c.locale.html" title="Locale">std.c.locale</a></li>
	<li><a href="std.c.math.html" title="Math">std.c.math</a></li>
	<li><a href="std.c.process.html" title="Process">std.c.process</a></li>
	<li><a href="std.c.stdarg.html" title="Variadic arguments">std.c.stdarg</a></li>
	<li><a href="std.c.stddef.html" title="Standard definitions">std.c.stddef</a></li>
	<li><a href="std.c.stdio.html" title="Standard I/O">std.c.stdio</a></li>
	<li><a href="std.c.stdlib.html" title="Standard library">std.c.stdlib</a></li>
	<li><a href="std.c.string.html" title="Strings">std.c.string</a></li>
	<li><a href="std.c.time.html" title="Time">std.c.time</a></li>
	<li><a href="std.c.wcharh.html" title="Wide characters">std.c.wcharh</a></li>
	<li><a href="std.windows.charset.html" title="Conversion to/from Windows character sets">std.windows.charset</a></li>
	<li><a href="phobos.html#std_windows" title="Modules specific to Windows">std.windows</a></li>
	<li><a href="phobos.html#std_linux" title="Modules specific to Windows">std.linux</a></li>
	<li><a href="phobos.html#std_c_windows" title="C Windows API">std.c.windows</a></li>
	<li><a href="phobos.html#std_c_linux" title="C Linux API">std.c.linux</a></li>
    </ul>
</div>
</div>
<div id="content">
    <h1><a href="./htmlsrc/std.utf.html">std.utf</a></h1>
    
Encode and decode UTF-8, UTF-16 and UTF-32 strings.<br><br>
For Win32 systems, the C wchar_t type is UTF-16 and corresponds to the D
 wchar type.
 For linux systems, the C wchar_t type is UTF-32 and corresponds to
 the D utf.dchar type. <br><br> UTF character support is restricted to &#40;\u0000 &lt;= character &lt;= \U0010FFFF&#41;.<br><br> <br><br>
<b>See Also:</b><br>
<a href="http://en.wikipedia.org/wiki/Unicode">Wikipedia</a><br>
	<a href="http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8">http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8</a><br>
	<a href="http://anubis.dkuug.dk/JTC1/SC2/WG2/docs/n1335">http://anubis.dkuug.dk/JTC1/SC2/WG2/docs/n1335</a><br><br>
<dl>
<dt><big>class <a href="./htmlsrc/std.utf.html#L49" title="At line 49.">UtfError</a> : Error; [deprecated]</big></dt>
<dd>
<dl>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L51" title="At line 51.">idx</a>;</big></dt>
<dd></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L53" title="At line 53.">this</a>(char[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd></dd></dl></dd>
<dt><big>class <a href="./htmlsrc/std.utf.html#L64" title="At line 64.">UtfException</a> : Exception;</big></dt>
<dd>
Exception class that is thrown upon any errors.
 <br><br>
<dl>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L66" title="At line 66.">idx</a>;</big></dt>
<dd>
index in string of where error occurred<br><br></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L68" title="At line 68.">this</a>(char[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd></dd></dl></dd>
<dt><big>bool <a href="./htmlsrc/std.utf.html#L85" title="At line 85.">isValidDchar</a>(dchar <i>c</i>);</big></dt>
<dd>
Test if c is a valid UTF-32 character.<br><br>
\uFFFE and \uFFFF are considered valid by this function,
 as they are permitted for internal use by an application,
 but they are not allowed for interchange by the Unicode standard.<br><br> <br><br>
<b>Returns:</b><br>
true if it is, false if not.<br><br></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L97" title="At line 97.">unittest</a>;</big></dt>
<dd></dd>
<dt><big>ubyte[256] <a href="./htmlsrc/std.utf.html#L105" title="At line 105.">UTF8stride</a>;</big></dt>
<dd></dd>
<dt><big>uint <a href="./htmlsrc/std.utf.html#L133" title="At line 133.">stride</a>(char[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd>
stride&#40;&#41; returns the length of a UTF-8 sequence starting at index i
 in string s.
 <br><br>
<b>Returns:</b><br>
The number of bytes in the UTF-8 sequence or
	0xFF meaning s[i] is not the start of of UTF-8 sequence.<br><br></dd>
<dt><big>uint <a href="./htmlsrc/std.utf.html#L143" title="At line 143.">stride</a>(wchar[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd>
stride&#40;&#41; returns the length of a UTF-16 sequence starting at index i
 in string s.
 <br><br></dd>
<dt><big>uint <a href="./htmlsrc/std.utf.html#L154" title="At line 154.">stride</a>(dchar[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd>
stride&#40;&#41; returns the length of a UTF-32 sequence starting at index i
 in string s.
 <br><br>
<b>Returns:</b><br>
The return value will always be 1.<br><br></dd>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L165" title="At line 165.">toUCSindex</a>(char[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L188" title="At line 188.">toUCSindex</a>(wchar[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L209" title="At line 209.">toUCSindex</a>(dchar[] <i>s</i>, size_t <i>i</i>);</big></dt>
<dd>
Given an index i into an array of characters s[],
 and assuming that index i is at the start of a UTF character,
 determine the number of UCS characters up to that index i.
 <br><br></dd>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L218" title="At line 218.">toUTFindex</a>(char[] <i>s</i>, size_t <i>n</i>);</big></dt>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L234" title="At line 234.">toUTFindex</a>(wchar[] <i>s</i>, size_t <i>n</i>);</big></dt>
<dt><big>size_t <a href="./htmlsrc/std.utf.html#L248" title="At line 248.">toUTFindex</a>(dchar[] <i>s</i>, size_t <i>n</i>);</big></dt>
<dd>
Given a UCS index n into an array of characters s[], return the UTF index.
 <br><br></dd>
<dt><big>dchar <a href="./htmlsrc/std.utf.html#L261" title="At line 261.">decode</a>(char[] <i>s</i>, inout size_t <i>idx</i>);</big></dt>
<dt><big>dchar <a href="./htmlsrc/std.utf.html#L403" title="At line 403.">decode</a>(wchar[] <i>s</i>, inout size_t <i>idx</i>);</big></dt>
<dt><big>dchar <a href="./htmlsrc/std.utf.html#L460" title="At line 460.">decode</a>(dchar[] <i>s</i>, inout size_t <i>idx</i>);</big></dt>
<dd>
Decodes and returns character starting at s[idx]. idx is advanced past the
 decoded character. If the character is not well formed, a UtfException is
 thrown and idx remains unchanged.
 <br><br></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L348" title="At line 348.">unittest</a>;</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.utf.html#L486" title="At line 486.">encode</a>(inout char[] <i>s</i>, dchar <i>c</i>);</big></dt>
<dt><big>void <a href="./htmlsrc/std.utf.html#L555" title="At line 555.">encode</a>(inout wchar[] <i>s</i>, dchar <i>c</i>);</big></dt>
<dt><big>void <a href="./htmlsrc/std.utf.html#L581" title="At line 581.">encode</a>(inout dchar[] <i>s</i>, dchar <i>c</i>);</big></dt>
<dd>
Encodes character c and appends it to array s[].
 <br><br></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L534" title="At line 534.">unittest</a>;</big></dt>
<dd></dd>
<dt><big>void <a href="./htmlsrc/std.utf.html#L598" title="At line 598.">validate</a>(char[] <i>s</i>);</big></dt>
<dt><big>void <a href="./htmlsrc/std.utf.html#L611" title="At line 611.">validate</a>(wchar[] <i>s</i>);</big></dt>
<dt><big>void <a href="./htmlsrc/std.utf.html#L624" title="At line 624.">validate</a>(dchar[] <i>s</i>);</big></dt>
<dd>
Checks to see if string is well formed or not. Throws a UtfException if it is
 not. Use to check all untrusted input for correctness.
 <br><br></dd>
<dt><big>char[] <a href="./htmlsrc/std.utf.html#L637" title="At line 637.">toUTF8</a>(char[4] <i>buf</i>, dchar <i>c</i>);</big></dt>
<dd></dd>
<dt><big>char[] <a href="./htmlsrc/std.utf.html#L677" title="At line 677.">toUTF8</a>(char[] <i>s</i>);</big></dt>
<dt><big>char[] <a href="./htmlsrc/std.utf.html#L689" title="At line 689.">toUTF8</a>(wchar[] <i>s</i>);</big></dt>
<dt><big>char[] <a href="./htmlsrc/std.utf.html#L717" title="At line 717.">toUTF8</a>(dchar[] <i>s</i>);</big></dt>
<dd>
Encodes string s into UTF-8 and returns the encoded string.
 <br><br></dd>
<dt><big>wchar[] <a href="./htmlsrc/std.utf.html#L745" title="At line 745.">toUTF16</a>(wchar[2] <i>buf</i>, dchar <i>c</i>);</big></dt>
<dd></dd>
<dt><big>wchar[] <a href="./htmlsrc/std.utf.html#L771" title="At line 771.">toUTF16</a>(char[] <i>s</i>);</big></dt>
<dt><big>wchar* <a href="./htmlsrc/std.utf.html#L797" title="At line 797.">toUTF16z</a>(char[] <i>s</i>);</big></dt>
<dt><big>wchar[] <a href="./htmlsrc/std.utf.html#L824" title="At line 824.">toUTF16</a>(wchar[] <i>s</i>);</big></dt>
<dt><big>wchar[] <a href="./htmlsrc/std.utf.html#L836" title="At line 836.">toUTF16</a>(dchar[] <i>s</i>);</big></dt>
<dd>
Encodes string s into UTF-16 and returns the encoded string.
 toUTF16z&#40;&#41; is suitable for calling the 'W' functions in the Win32 API that take
 an LPWSTR or LPCWSTR argument.
 <br><br></dd>
<dt><big>dchar[] <a href="./htmlsrc/std.utf.html#L856" title="At line 856.">toUTF32</a>(char[] <i>s</i>);</big></dt>
<dt><big>dchar[] <a href="./htmlsrc/std.utf.html#L877" title="At line 877.">toUTF32</a>(wchar[] <i>s</i>);</big></dt>
<dt><big>dchar[] <a href="./htmlsrc/std.utf.html#L898" title="At line 898.">toUTF32</a>(dchar[] <i>s</i>);</big></dt>
<dd>
Encodes string s into UTF-32 and returns the encoded string.
 <br><br></dd>
<dt><big><a href="./htmlsrc/std.utf.html#L910" title="At line 910.">unittest</a>;</big></dt>
<dd></dd></dl>
    <br><br>
<br><br>
<!-- Google ad -->
<script type="text/javascript"><!--
/**/google_ad_client = "pub-5628673096434613";
/**/google_ad_width = 728;
/**/google_ad_height = 90;
/**/google_ad_format = "728x90_as";
/**/google_ad_channel ="6203743411";
/**/google_page_url = document.location;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div id="copyright">
Copyright &copy; 1999-2008 by Digital Mars, All Rights Reserved |
Page generated by <a href="http://code.google.com/p/dil">dil</a> on Wed Oct  1 23:47:53 2008
</div>

</body>
</html>